package com.jcb.countfrench.presenter;


import android.content.Context;
import android.util.Log;
import android.view.View;

import com.jcb.countfrench.MainActivity;
import com.jcb.countfrench.dao.CountFrenchDAO;
import com.jcb.countfrench.model.Quizz;
import com.jcb.countfrench.model.QuizzQuestionReponse;
import com.jcb.countfrench.model.User;

public class QuizzPresenter {
	private User user ;
	private CountFrenchDAO countFrenchDAO ;
	Context context ;
	MainActivity mainActivity ;
	static int counter = 0 ;
	
	 public QuizzPresenter(User user, CountFrenchDAO countFrenchDAO, Context context, MainActivity mainActivity) {
		super();
		this.user = user;
		this.countFrenchDAO = countFrenchDAO;
		this.context = context;
		this.mainActivity = mainActivity ;
	}

	public void switchView(View v) {
		mainActivity.setContentView(v);
	}
	

	public void setLearningView() {
		mainActivity.setContentView(mainActivity.getLearnView());
	}
	
	public QuizzQuestionReponse nextItem(Quizz quizz ) {		
		Log.d("TAG", "nextItem=" );
		QuizzQuestionReponse next = countFrenchDAO.getNextQuestion(quizz.getCurrentQuizzQuestionReponse(),quizz.getIdQuizz());		
		if (next != null) {
			Log.d("TAG", "nextItem=" + next.getSolution() );
			quizz.addQuizzQuestionReponse(next);
		}
		return next;
	}

	public void traiteReponseUser(String solutionUser,Quizz quizz, QuizzQuestionReponse quizzQuestionReponse) {
		if (quizzQuestionReponse != null) {
			if (solutionUser.equalsIgnoreCase(quizzQuestionReponse.getSolution()) ) {
				quizz.setNbReponseOK(quizz.getNbReponseOK() + 1);
				quizz.setInfoQuestion( "Good !!!");	
			}
			else {
				quizz.setInfoQuestion("No !!!");
				quizz.setNbReponseErr(quizz.getNbReponseErr() + 1);
			}
		} else {
			quizz.setInfoQuestion("Quizz finished");
		}
	}
	
	
}
